/*
 * jlb
 */
package com.jlb.core.tools.redis;


import com.jlb.core.common.Constants;
import com.jlb.core.tools.AreaTools;

public class RedisKey {

    /**
     * 生成区域编码
     *
     * @param code 编码
     * @return
     */
    public static String genAreaKey(String code) {
        int level;
        // 比较省份缓存key，返回省份级别
        if (code.equals(Constants.PROVICES_DEFAULT_REDISKEY)) level = 1;
            // 根据传入编码获取对应级别
        else level = AreaTools.getAreaLevel(code.substring(code.indexOf(":") + 1, code.length()));

        String redis_mid_key = "";
        switch (level) {
            case 1:
                redis_mid_key = "provices:";
                break;
            case 2:
                redis_mid_key = "citys:";
                break;
            case 3:
                redis_mid_key = "countys:";
                break;
            case 4:
                redis_mid_key = "towns:";
                break;
            default:
                break;
        }
        return "BasicArea:" + redis_mid_key + code;
    }

    /**
     * 生成用户注册缓存key,防止多次提交
     *
     * @param key 编码
     * @return
     */
    public static String genReg(String key) {
        return "JLB:UserReg:" + key;
    }

}
